package edu.neu.cs6515.hci;

import java.util.LinkedList;
import java.util.List;

import lombok.Getter;
import lombok.Setter;
import edu.neu.cs6515.board.HexagonBoard;
import edu.neu.cs6515.player.strategy.AbstractStrategy;
import edu.neu.cs6515.player.strategy.StrategyException;
import edu.neu.cs6515.xml.Placement;
import edu.neu.cs6515.xml.Score;
import edu.neu.cs6515.xml.Tile;

/**
 * Strategy for human players
 */
public class HCIStrategy extends AbstractStrategy {

    private HCIPanel hciPanel;

    @Getter
    private int interval;

    /**
     * C'tor for HCIStrategy
     * 
     * @param interval
     *            number of seconds for a human player to make a placement
     */
    public HCIStrategy(final int interval, final HCIPanel hciPanel) {
        super();
        this.interval = interval;
        this.hciPanel = hciPanel;
    }

    @Override
    public Placement getNextMove(final List<Tile> tilesInHand,
            final int numberOfPlayers, final List<Placement> placementsSofar,
            final Score scoreBeforePlacement) {
        List<Placement> lp = hciPanel.waitAndGetUserPlacement(initializeHexagonBoard(numberOfPlayers,
                placementsSofar), tilesInHand, scoreBeforePlacement);
        if (lp.size() == 0) {
            throw new StrategyException("");
        }
        return lp.get(0);
    }

    /**
     * Makes a HexagonBoard object that represents the current board
     * from a list of placements made.
     * @param numberOfPlayers 
     * @param placementsSofar 
     * @return HexagonBoard object
     */
    private HexagonBoard initializeHexagonBoard(final int numberOfPlayers,
            final List<Placement> placementsSofar) {
        HexagonBoard hexagonBoard = new HexagonBoard(numberOfPlayers);
        hexagonBoard.updateHexagonBoard(placementsSofar);
        return hexagonBoard;
    }
}
